<?php
//测试号相关信息
$mdKey = 'fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW2ysRR';
$mid = '898340149000005';
$tid = '88880001';
$requestTimestamp = date('Y-m-d H:i:s',time());
$data = [
    'msgSrc' => 'WWW.TEST.COM',//消息来源
    'msgType' => 'refund',//消息类型
    'requestTimestamp' => $requestTimestamp,//报文请求时间
    'merOrderId' => $merOrderId,//订单号
    'instMid' => $params['instMid'],//业务类型
    'mid' => $mid,//商户号
    'tid' => $tid,//终端号
    'refundAmount' => 1,//退款金额
    'refundDesc' => '测试',//退款说明
];
ksort($data);
reset($data);
$options = '';
foreach ($data as $key => $value) {
    $options .= $key . '=' . $value .'&';
}
$options = rtrim($options, '&');
//存在转义字符，那么去掉转义
if(get_magic_quotes_gpc()){
    $options = stripslashes($options);
}
//签名
$sign = md5($options . $mdKey);
$data['sign'] = $sign;
$client = new Client();
$response = $client->createRequest()
    ->setMethod('POST')
    ->setUrl('https://qr-test2.chinaums.com/netpay-route-server/api/')
    ->setData($data)
    ->setHeaders([
        'Content-Type'=>'application/json'
    ])
    ->setFormat(Client::FORMAT_JSON) //提交的数据的格式
    ->send();
if ($response->isOk) {
    $data = $response->data;
    if ($data['refundStatus'] == 'SUCCESS') {
        //退款成功
        return true;
    }
}
return false;
}
?>